package com.foosun.util.wechat;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.foosun.util.https.HttpClientConnectionManager;
  
/** 
 * 微信自定义菜单创建 
 */  
public class WxConnectUtils {  
    // http客户端  
    public static DefaultHttpClient httpclient;  
      
    static {  
        httpclient = new DefaultHttpClient();  
        httpclient = (DefaultHttpClient) HttpClientConnectionManager.getSSLInstance(httpclient); // 接受任何证书的浏览器客户端  
    }  
  
    public static void main(String[] args) {  
        try {  
        	String data = "<xml><ToUserName><![CDATA[mycreate]]></ToUserName><FromUserName><![CDATA[wx5823bf96d3bd56c7]]></FromUserName><CreateTime>1348831860</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[this is a test]]></Content><MsgId>1234567890123456</MsgId><AgentID>128</AgentID></xml>";
        	WxConnectUtils connectUtils = new WxConnectUtils();
        	connectUtils.sendMsg(data);
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
    }  
      
      
    /** 
     * 创建菜单 
     */  
    public static void sendMsg(String params) throws Exception {  
        HttpPost httpost = HttpClientConnectionManager.getPostMethod("http://127.0.0.1:8080/schat/service.htm?msg_signature=477715d11cdb4164915debcba66cb864d751f3e6&timestamp=1409659813&nonce=1372623149");
        httpost.addHeader("Content-Type", "text/xml; charset=UTF-8");
        httpost.setEntity(new StringEntity(params, "UTF-8"));  
        HttpResponse response = httpclient.execute(httpost);  
    }  
      
}  
